/**
 * 
 */
package org.xlab.baseframework.web.component;

import org.xlab.baseframework.domain.query.SystemLogQueryObject;
import org.xlab.baseframework.system.Declare;
import org.xlab.baseframework.web.data.LogSearchFormFieldFactory;

import com.vaadin.data.util.BeanItem;
import com.vaadin.ui.Field;
import com.vaadin.ui.Form;
import com.vaadin.ui.GridLayout;

/**
 * @author MaKuBEX
 * 
 */
public class LogSearchForm extends Form {

	/**
	 * @serialField
	 */
	private static final long serialVersionUID = 6319995886219207301L;

	private GridLayout gridLayout;

	public LogSearchForm(BeanItem<SystemLogQueryObject> systemLogQueryObject) {

		this.gridLayout = new GridLayout(4, 4);
		this.gridLayout.setWidth(Declare.HUNDRED_PERCENT);

		this.gridLayout.setMargin(false, false, false, false);
		this.gridLayout.setSpacing(true);
		super.setLayout(this.gridLayout);
		super.setInvalidCommitted(false);
		super.setFormFieldFactory(new LogSearchFormFieldFactory());
		super.setItemDataSource(systemLogQueryObject);
		super.setVisibleItemProperties(new Object[] {
				SystemLogQueryObject.FIELD_MIN_LOGLEVEL,
				SystemLogQueryObject.FIELD_MAX_LOGLEVEL,
				SystemLogQueryObject.FIELD_MIN_CREATED_TIME,
				SystemLogQueryObject.FIELD_MAX_CREATED_TIME,
				SystemLogQueryObject.FIELD_TITLE,
				SystemLogQueryObject.FIELD_CONTENT });
	}

	/**
	 * @see com.vaadin.ui.Form#attachField(java.lang.Object,
	 *      com.vaadin.ui.Field)
	 */
	protected void attachField(Object propertyId, Field field) {
		if (propertyId.equals(SystemLogQueryObject.FIELD_TITLE)) {
			this.gridLayout.addComponent(field, 0, 2, 1, 2);
		} else if (propertyId.equals(SystemLogQueryObject.FIELD_CONTENT)) {
			this.gridLayout.addComponent(field, 2, 2, 3, 2);
		} else {
			this.gridLayout.addComponent(field);
		}
	}

}
